package com.zyf.service;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@Slf4j
@MapperScan("com.zyf.service.dao")
public class ServiceApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
//        SpringApplication.run(ServiceApplication.class, args);
        ConfigurableApplicationContext context = SpringApplication.run(ServiceApplication.class, args);

        Environment environment = context.getBean(Environment.class);
        //environment.getProperty("server.servlet.context-path") 应用的上下文路径，也可以称为项目路径
        String path = environment.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        log.info("\n访问地址：http://localhost:{}{}", environment.getProperty("server.port"), path);
        log.info("\n文档地址：http://localhost:{}{}/doc.html",environment.getProperty("server.port"), path);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
        http://localhost:8080/img/0a3b3288-3446-4420-bbff-f263d0c02d8e.jpg
        下面配置的大概意思就是，只有在url中是以img开头（如：http://localhost:8080/img）+ 文件名
        就到文件夹中如（F:\fff\img\）找到对应的图片或视频
         */
        registry.addResourceHandler("/getViewTs/**").addResourceLocations("file:C:\\Users\\Administrator\\Downloads\\Telegram Desktop\\");
    }


}
